package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.ReportService;
import com.sky.vo.OrdersStatisticsVO;
import com.sky.vo.OrdersTop10VO;
import com.sky.vo.TurnoverReportVO;
import com.sky.vo.UserStatisticsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@RequestMapping("/admin/report/")
@Slf4j
@Api(tags = "统计相关操作")
public class ReportController {

    @Autowired
    private ReportService reportService;

    @GetMapping("/turnoverStatistics")
    @ApiOperation("营业额统计接口")
    public Result<TurnoverReportVO> turnoverStatistics(@DateTimeFormat(pattern="yyyy-MM-dd") LocalDate begin,@DateTimeFormat(pattern="yyyy-MM-dd") LocalDate end){
        log.info("营业额统计请求 begin="+begin+"...end="+end);
        TurnoverReportVO vo=reportService.turnoverStatistics(begin,end);
        return Result.success(vo);
    }
    @GetMapping("/userStatistics")
    @ApiOperation("用户统计接口")
    public Result<UserStatisticsVo> userStatistics(@DateTimeFormat(pattern="yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern="yyyy-MM-dd") LocalDate end){
        UserStatisticsVo vo=reportService.userStatistics(begin,end);
        return Result.success(vo);
    }
    @GetMapping("/ordersStatistics")
    @ApiOperation("订单统计接口")
    public Result<OrdersStatisticsVO> ordersStatistics(@DateTimeFormat(pattern="yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern="yyyy-MM-dd") LocalDate end){
        OrdersStatisticsVO vo=reportService.ordersStatistics(begin,end);
        return Result.success(vo);
    }
    @GetMapping("/top10")
    @ApiOperation("查询销量排名top10")
    public Result<OrdersTop10VO> top10(@DateTimeFormat(pattern="yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern="yyyy-MM-dd") LocalDate end){
        OrdersTop10VO vo=reportService.top10(begin,end);
        return Result.success(vo);
    }
}
